import { Body, Controller, Get, HttpException, Post } from '@nestjs/common';
import { ForumService } from './service';
import  type { forumDto } from './dto';

@Controller('forum')
export class ForumController {
  constructor(private readonly forumService: ForumService) {}

  @Get("/getForumList")
  getForumList(@Body() body: forumDto) {
    return this.forumService.getForumList();
  }
}

// ##获取帖子列表
// @checkLoginHandling
// def getForumList(request):
//     json_data = json.loads(request.body)
//     pageSize = json_data.get("pageSize", 20)
//     currentPage = json_data.get("currentPage", 1)
//     openid = None
//     if json_data.get("openid"):
//         openid = json_data.get("openid")
//     sql = """SELECT d.content,d.discuss_index,u.nick_name,d.suport_count,u.img_url,d.suport_user,d.id,d.create_time,u.openid
//                        FROM discuss d left JOIN user u ON d.openid = u.openid
//                        where d.discuss_index = 0"""
//     if openid:
//         sql = sql + f""" and u.openid = '{openid}'"""
//     _, result = DBUtil.execute_select(sql)
//     paginator = Paginator(result, pageSize)
//     totalPage = paginator.num_pages
//     current_data = paginator.get_page(currentPage)
//     for item in current_data.object_list:
//         item["suport_user"] =json.loads(item["suport_user"])
//         item["create_time"] = handletime(item["create_time"])
//     return HttpSuccess(data=HttpPage(current_data.object_list, totalPage))
